package br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.admin.leftmenu.user;

import br.edu.ufcg.lsd.wbis.ui.client.beans.UserInfo;
import br.edu.ufcg.lsd.wbis.ui.client.beans.UserMatcher;
import br.edu.ufcg.lsd.wbis.ui.client.ui.FormManager;
import br.edu.ufcg.lsd.wbis.ui.client.ui.SubmitFormButtonListener;
import br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.admin.searchusers.ShowSearchedUsersTab;
import br.edu.ufcg.lsd.wbis.ui.client.ui.management.InfoManager;

import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.MessageBox;
import com.gwtext.client.widgets.TabPanel;
import com.gwtext.client.widgets.Window;

/**
 * @author Renato Miceli
 */
public class SearchButtonListener extends SubmitFormButtonListener<UserMatcher> {

	InfoManager<UserInfo> loggedManager;
	TabPanel centerPanel;
	
	public SearchButtonListener(Window enclosingWindow, TabPanel centerPanel, InfoManager<UserInfo> loggedManager, FormManager<UserMatcher> formManager) {
		super(enclosingWindow, formManager);
		this.centerPanel = centerPanel;
		this.loggedManager = loggedManager;
	}

	@Override
	public void onClick(Button button, EventObject e) {
		MessageBox.confirm("Confirm", "Do you confirm the search? ", new MessageBox.ConfirmCallback() {
			public void execute(String btnID) {
				if (btnID.equals("yes")) {
					ShowSearchedUsersTab panel = new ShowSearchedUsersTab(getParsedInfo(), centerPanel, loggedManager);
					centerPanel.add(panel);
					centerPanel.activate(panel.getId());
					getEnclosingWindow().destroy();
				}
			}
		});
	}

}
